package com.example.hello.client.TextArea;

import com.example.hello.BootstrapTextArea;
import com.github.gwtbootstrap.client.ui.constants.ResizeType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ValueBoxBase;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapTextArea.class)
public class BootstrapTextAreaConnector extends AbstractComponentConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapTextArea.class);
    }

    @Override
    public VBootstrapTextArea getWidget() {
        return (VBootstrapTextArea) super.getWidget();
    }

    @Override
    public BootstrapTextAreaState getState() {
        return (BootstrapTextAreaState) super.getState();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapTextAreaState state = getState();

        VBootstrapTextArea textArea = getWidget();

        textArea.setAlignment(ValueBoxBase.TextAlignment.valueOf(state.getAlignment()));
        textArea.setCharacterWidth(state.getCharacterWidth());
        textArea.setCursorPos(state.getCursorPos());
        textArea.setPlaceholder(state.getPlaceholder());
        textArea.setResize(ResizeType.valueOf(state.getResize()));
        textArea.setVisibleLines(state.getVisibleLines());
    }

}
